﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DotNetExtensions.AspNet.Http
{
    public class HttpRequest
    {
        public HttpRequest()
        {
            Cookies = new CookieCollection();
            Headers = new HeaderCollection();
            MultipartForms = new List<MultipartFormDataItem>();
        }

        public CookieCollection Cookies { get; }
        public HeaderCollection Headers { get; }
        public Encoding Encoding { get; set; }
        public string ContentType { get; set; } = "application/json";
        public byte[] Content { get; set; }
        public List<MultipartFormDataItem> MultipartForms { get;}

        public string StringContent
        {
            get
            {
                if (this.Encoding == null) this.Encoding = Encoding.UTF8;
                return (Content == null || Content.Length == 0) ? string.Empty : this.Encoding.GetString(Content);
            }
            set
            {
                if (this.Encoding == null) this.Encoding = Encoding.UTF8;
                Content = this.Encoding.GetBytes(value);
            }
        }
    }
}
